package com.syedu.day04.homework;

/**
 * description：最大公约数和最小公倍数
 */
public class DivisorNumber {
    public static void main(String[] args) {
        int gcd = gcd(27, 18);
        System.out.println(gcd);

        int lcm = lcm(27, 18);
        System.out.println(lcm);
    }

    /**
     * 写一个方法,获取两个数的最大公约数
     */
    public static int gcd(int num1, int num2) {
        int temp = num1 % num2;
        while (temp != 0) {
            num1 = num2;
            num2 = temp;
            temp = num1 % num2;
        }
        return num2;
    }

    /**
     * 写一个方法,获取两个数的最小公倍数
     */
    public static int lcm(int num1, int num2) {
        return num1 * num2 / gcd(num1, num2);
    }
}